using System.Text.RegularExpressions;
using NUnit.Framework;
using WatiN.Core;

namespace Headspring.Training.FullSystemTests
{
	[TestFixture, Explicit]
	public class LoginTester : BaseTester
	{
		[Test]
		public void Should_Navigate_Away_From_Login_Page_On_Successful_Login()
		{
			SelectList userList = _browser.SelectList(new Regex("username"));
			Button submitButton = _browser.Button(Find.By("type", "submit"));

			userList.Select("Jeffrey Palermo");
			_browser.TextField("password").TypeText("beer");
			submitButton.Click();

			StringAssert.Contains("Jeffrey Palermo", _browser.Text);
			StringAssert.Contains("search/list", _browser.Url);
		}

		[Test]
		public void Should_show_error_message_on_bad_password()
		{
			SelectList userList = _browser.SelectList(new Regex("username"));
			Button submitButton = _browser.Button(Find.By("type", "submit"));

			userList.Select("Jeffrey Palermo");
			_browser.TextField("password").TypeText("wrong");
			submitButton.Click();

			StringAssert.Contains("Login incorrect", _browser.Text);
		}
	}
}